import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  CaptchaResult,
  LoginData,
  CourseLoginData,
  LoginResult,
  phoneLoginData,
  PhoneCaptchaResult,
  phoneLoginDatato,
  RegisterData,
  forgetData,
} from "./types";

/**
 * 登录API
 *
 * @param data {LoginData}
 * @returns
 */
export function loginApi(data: LoginData): AxiosPromise<LoginResult> {
  return request({
    url: "/api/v1/auth/login",
    method: "post",
    params: data,
  });
}

/**
 * 课程登录API
 *
 * @param data {CourseLoginData}
 * @returns
 */
export function enterCourseApi(
  data: CourseLoginData
): AxiosPromise<LoginResult> {
  return request({
    url: "/api/v1/auth/enterCourse",
    method: "post",
    params: data,
  });
}

/**
 * 注销API
 */
export function logoutApi() {
  return request({
    url: "/api/v1/auth/logout",
    method: "delete",
  });
}

/**
 * 获取验证码API
 */
export function getCaptchaApi(): AxiosPromise<CaptchaResult> {
  return request({
    url: "/api/v1/auth/captcha",
    method: "get",
  });
}

/**
 * 手机验证码登录API
 *
 * @param data {phoneLoginData}
 * @returns
 */
export function phoneloginApi(data: phoneLoginData): AxiosPromise<LoginResult> {
  return request({
    url: "/api/v1/auth/phoneLogin",
    method: "post",
    params: data,
  });
}

/**
 * 获取手机验证码API
 * @param data {phoneLoginDatato}
 * @returns
 */
export function getPhoneCaptchaApi(
  data: phoneLoginDatato
): AxiosPromise<PhoneCaptchaResult> {
  return request({
    url: "/api/v1/auth/smsCode",
    method: "get",
    params: data,
  });
}

/**
 * 注册API
 *
 * @param data {RegisterData}
 * @returns
 */
export function registrApi(data: RegisterData): AxiosPromise<LoginResult> {
  return request({
    url: "/api/v1/auth/register",
    method: "post",
    params: data,
  });
}

/**
 * 忘记密码API
 *
 * @param data {forgetData}
 * @returns
 */
export function forgetApi(data: forgetData): AxiosPromise<LoginResult> {
  return request({
    url: "/api/v1/auth/forgetPwd",
    method: "post",
    params: data,
  });
}
